package com.fdd.op.sdk;

import com.fdd.op.sdk.internal.util.FddHashMap;

import java.util.Map;
import java.util.UUID;

/**
 * 基础Fdd请求类，存放一些通用的请求参数。注：这个类不能随意增加get/set/is开头类的方法，否则会有可能和API业务级的参数冲突。
 *
 * @author Fadada
 * @date 2021/04/26
 */
public abstract class BaseFddRequest<T extends FddResponse> implements FddRequest<T> {
	/**
	 * HTTP请求头参数
	 */
	protected Map<String, Object> headerMap;
	/**
	 * 自定义表单参数
	 */
	protected FddHashMap udfParams;
	/**
	 * 请求时间戳
	 */
	protected Long timestamp;
	/**
	 * 请求目标AppKey
	 */
	protected String targetAppKey;
	/**
	 * 指定哪个入参是混淆参数
	 */
	protected String fddMixParams;
	/**
	 * 使用批量API调用时，每个API可以使用不同的授权码，普通API调用忽略此属性
	 */
	protected String session;
	/**
	 * 标示该API在批量API调用中的顺序
	 */
	protected int order;

	private String httpMethod = "POST";
	/**
	 * 客户端生成请求id
	 */
	private String reqId = UUID.randomUUID().toString();

	/**
	 * 添加URL自定义请求参数。
	 */
	public void putOtherTextParam(String key, Object value) {
		if (this.udfParams == null) {
			this.udfParams = new FddHashMap();
		}
		this.udfParams.put(key, value);
	}

	@Override
	public Map<String, Object> getHeaderMap() {
		if (this.headerMap == null) {
			this.headerMap = new FddHashMap();
		}
		return this.headerMap;
	}

	public void setHeaderMap(Map<String, Object> headerMap) {
		this.headerMap = headerMap;
	}

	/**
	 * 添加头部自定义请求参数。
	 */
	public void putHeaderParam(String key, Object value) {
		getHeaderMap().put(key, value);
	}

	@Override
	public Long getTimestamp() {
		return this.timestamp;
	}

	public void setTimestamp(Long timestamp) {
		this.timestamp = timestamp;
	}

	@Override
	public String getTargetAppKey() {
		return this.targetAppKey;
	}

	public void setTargetAppKey(String targetAppKey) {
		this.targetAppKey = targetAppKey;
	}

	public String getFddMixParams() {
		return this.fddMixParams;
	}

	public void setFddMixParams(String fddMixParams) {
		this.fddMixParams = fddMixParams;
	}

	@Override
	public String getBatchApiSession() {
		return this.session;
	}

	@Override
	public void setBatchApiSession(String session) {
		this.session = session;
	}

	@Override
	public int getBatchApiOrder() {
		return this.order;
	}

	@Override
	public void setBatchApiOrder(int order) {
		this.order = order;
	}

	public void setHttpMethod(String httpMethod) {
		this.httpMethod = httpMethod;
	}

	@Override
	public String getHttpId() {
		return reqId;
	}

}
